home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 April / CHIP 1996 aprilis (CD06).zip / CHIP_CD06.ISO / microsft / vb4 / vb4-4.cab / alarm.frm next >
Text File  |  1995-08-15  |  3KB  |  104 lines

  1. VERSION 4.00
  2. Begin VB.Form AlarmForm 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Alarm Clock"
  5.    ClientHeight    =   780
  6.    ClientLeft      =   1230
  7.    ClientTop       =   1635
  8.    ClientWidth     =   3135
  9.    BeginProperty Font 
  10.       name            =   "MS Sans Serif"
  11.       charset         =   1
  12.       weight          =   700
  13.       size            =   8.25
  14.       underline       =   0   'False
  15.       italic          =   0   'False
  16.       strikethrough   =   0   'False
  17.    EndProperty
  18.    Height          =   1185
  19.    Icon            =   "ALARM.frx":0000
  20.    Left            =   1170
  21.    LinkTopic       =   "Form2"
  22.    MaxButton       =   0   'False
  23.    ScaleHeight     =   780
  24.    ScaleWidth      =   3135
  25.    Top             =   1290
  26.    Width           =   3255
  27.    Begin VB.Timer Timer1 
  28.       Interval        =   500
  29.       Left            =   2640
  30.       Top             =   120
  31.    End
  32.    Begin VB.Label lblTime 
  33.       BeginProperty Font 
  34.          name            =   "MS Sans Serif"
  35.          charset         =   1
  36.          weight          =   700
  37.          size            =   12
  38.          underline       =   0   'False
  39.          italic          =   0   'False
  40.          strikethrough   =   0   'False
  41.       EndProperty
  42.       Height          =   495
  43.       Left            =   120
  44.       TabIndex        =   0
  45.       Top             =   120
  46.       Width           =   2415
  47.    End
  48. End
  49. Attribute VB_Name = "AlarmForm"
  50. Attribute VB_Creatable = False
  51. Attribute VB_Exposed = False
  52. Option Explicit
  53. Dim AlarmTime
  54. Const conMinimized = 1
  55.  
  56.  
  57. Private Sub Form_Click()
  58.     AlarmTime = InputBox("Enter alarm time", "VB Alarm", AlarmTime)
  59.     If AlarmTime = "" Then Exit Sub
  60.     If Not IsDate(AlarmTime) Then
  61.         MsgBox "The time you entered was not valid."
  62.     Else                                    ' String returned from InputBox is a valid time,
  63.         AlarmTime = CDate(AlarmTime)        ' so store it as a date/time value in AlarmTime.
  64.     End If
  65. End Sub
  66.  
  67. Private Sub Form_Load()
  68.     AlarmTime = ""
  69. End Sub
  70.  
  71. Private Sub Form_Resize()
  72.     If WindowState = conMinimized Then      ' If form is minimized, display the time in a caption.
  73.         SetCaptionTime
  74.     Else
  75.         Caption = "Alarm Clock"
  76.     End If
  77. End Sub
  78.  
  79. Private Sub SetCaptionTime()
  80.     Caption = Format(Time, "Medium Time")   ' Display time using medium time format.
  81. End Sub
  82.  
  83. Private Sub Timer1_Timer()
  84. Static AlarmSounded As Integer
  85.     If lblTime.Caption <> CStr(Time) Then
  86.         ' It's now a different second than the one displayed.
  87.         If Time >= AlarmTime And Not AlarmSounded Then
  88.             Beep
  89.             MsgBox "Alarm at " & Time
  90.             AlarmSounded = True
  91.         ElseIf Time < AlarmTime Then
  92.             AlarmSounded = False
  93.         End If
  94.         If WindowState = conMinimized Then
  95.             ' If minimized, then update the form's Caption every minute.
  96.             If Minute(CDate(Caption)) <> Minute(Time) Then SetCaptionTime
  97.         Else
  98.             ' Otherwise, update the label Caption in the form every second.
  99.             lblTime.Caption = Time
  100.         End If
  101.     End If
  102. End Sub
  103.  
  104.